class Balance
  include DataMapper::Resource

  property :id,         Integer, :key => true 
  property :bitcoin,    Float 
  property :usd,        Float
  property :updated_at, DateTime
  
  @@id = 0
  @@bal = nil
  
  def Balance.instance
    @@bal = Balance.get(@@id)
    if @@bal.nil?
      @@bal = Balance.create(:id => @@id, :bitcoin => 0, :usd => 0, :updated_at => Time.now);
    end
    return @@bal      
  end
  
  def update_instance
    self.updated_at = Time.now
    save
    puts "Child update_instance"
  end
    
  def to_s
    return "Bitcoins: #{self.bitcoin.to_s} \t USD:#{self.usd.to_s} \t Updated at #{self.updated_at.to_s}"          
  end
end